# _*_ coding:utf-8 _*_
# @Time : 2023/5/25 17:57
# @Author : wsl
# @File : day05_demo
# @Project : python  xpath解析 安装lxmp库 E:\python\Scripts   c+s+x

from lxml import etree

# 解析本地文件
tree = etree.parse('xpth.html')

# 路径查询  //：不考虑子节点  /:子节点
li_list = tree.xpath('//body/ul/li')
# 谓词查询
li_list = tree.xpath('//ul/li[@id]/text()')
# 内容查询
li_list = tree.xpath('//ul/li[@id="l1"]/text()')

# 属性查询
li_list = tree.xpath('//ul/li[@id="l1"]/@class')

# 逻辑查询
# and
li_list = tree.xpath('//ul/li[@id="l1" and  @class="c1"]/text()')
# |
li_list = tree.xpath('//ul/li[@id="l1"]/text() | //ul/li[@id="l2"]/text()')

# 模糊查询
# 包含
li_list = tree.xpath('//ul/li[contains(@id,"l")]/text()')
# 开始
li_list = tree.xpath('//ul/li[starts-with(@id,"c")]/text()')

li_list = tree.xpath('//ul/li[starts-with(@id,"c")]/text()')

li_list = tree.xpath('//title/text() ')
print(li_list)